import { Result } from '@/service/request/type';
import { Message } from '@/instance';

export default (tableRef: any, doEditAction: (data: any) => Promise<Result<any>>) => {
    /**
     * @: 行内编辑
     * @param {T} row
     * @return {*}
     */
    const rowEdit = async function <T>(data: T, row: any) {
        try {
            row.btnSaveLoading = true;
            const res = await doEditAction(data);

            Message.success('操作成功！');

            return res;
        } catch (error) {
            console.log('error', error);
        } finally {
            row.btnSaveLoading = false;
        }
    };

    return {
        rowEdit
    };
};
